var lodo_jcarousel;
var product_wholesale={};
var OAitems = {};
var sellProps;
var allItems;
var mealDetailPrice;
var defaultSelect;
var sellProperty = {};
var cartbtnsumitName = "#ark_addToCart";
var thumblist="thumblist";
var ShoppingCart = (function() {
	var Q = lodo_lang_js.arkShopCart.tip_1;//此商品缺货中
    var N = lodo_lang_js.arkShopCart.tip_2;//请选择：
    var K = lodo_lang_js.arkShopCart.tip_3;//请填写正确的商品数量！
    var U = lodo_lang_js.arkShopCart.tip_4;//您是卖家，不能添加到购物车
    var O = new cart_r_cls();
    var I = function(g) {
        O.show($(cartbtnsumitName));
        O.reportFailed(g);
    };
    var E = function() {
        var j = $("#ark_listCart");
        if (!j[0]) {
            I(U);
            return false
        }
        if (typeof(sellProperty[productID]) != "undefined") {
            if (!sellProperty[productID].isAllPVSelected()) {
                var k = sellProperty[productID].getUnselectedPVNames().join('", "');
                I(N + ' "' + k + '"');
                $("#ark_info-hx").html("<em>" + N + ' "' + k + '"</em>');
                return false
            }
        }
        var m = $("#ark_buy_maxCount");
        var l = $("#ark_buyqn");
        if (!m[0]) {
            return false
        }
        if (!l[0]) {
            return false
        };
        var i = /^[1-9]\d*$/;
        if (!i.test(l.val().replace(/(^\s*)|(\s*$)/g, ""))) {
            I(K);
            return false
        };
        var h = parseInt(l.val());
        var g = parseInt(m.val());
        var lv = l.attr("lv");
        var lvtyp = l.attr("lvtyp");
        if (g == 0) {
            I(Q);
            return false
        }
        if (h > g && g != -1) {
            I(lodo_lang_js.arkShopCart.tip_5.replace("{$1}",g));
            return false
        }
		
		if(lvtyp==0){
		if ( (h<=0 || (h % lv) != 0)){
				I(lodo_lang_js.arkShopCart.tip_6.replace("{$1}",lv));
				return false;
			}
		}else{
			if(h<lv){
				I(lodo_lang_js.arkShopCart.tip_7.replace("{$1}",lv));
				return false;
			}
		}
        return true
    };
    var E_Fit = function() {
        return true
    };
    var a = {};
    var goods_cart_btn = false;
    a.attachEventToAddTrigger = function() {
        $("#ark_sellProperty_area").hover(function() {
            $(this).addClass("no-selceted");
            return false
        },function() {
            $(this).removeClass("no-selceted");
            return false
        });
        $("#ark_addToCart,#ark_nowbuyToCart,#addFitToCart,#btn_goods_pointsexchange,#mypanicbuying,#ark_addmake").bind("click",function() {
            var Buyhrefno = $("#ark_addToCart").attr("Buyhrefno");
            if (Buyhrefno == "1") {
                location.href = $("#ark_addToCart").attr("Buyhref");
                return;
            };
            cartbtnsumitName = "#" + this.id;
            if (!!E()) {
                goods_cart_btn = true;
                var k = $("#ark_buy_itemId").val();
                var g = $("#ark_buy_itemDetailId").val();
                var i = $("#ark_buyqn").val();
                var cgi = $("#ark_buy_cgid").val();
                var act = "buy";
                if (!cgi) {
                    cgi = 0;
                };
                switch (this.id) {
					case "ark_nowbuyToCart":{
							a.pro_post_cart2(k, g, i);
							return false;
							break;
						}
					case "addFitToCart":{
							if (!E_Fit()) {
								return false;
							}
							act = "buyfit";
							break;
						}
					case "btn_goods_pointsexchange":{
							act = "buyjfyh";
							break;
						}
					case "mypanicbuying":{
							act = "buycg";
							break;
						}
					case "ark_addmake":{
							addtomake(k, g, i);
							return false;
							break;
						}
                };
                var j = [act, k, g, i, cgi];
                var Comm_options = {
                    action: function() {
                        a.addToCart(j);
                    }
                };
				window._PP_core_GoodsJfyhComm_data = Comm_options;
                if (act == "buyjfyh") {
                    window._PP_core_GoodsJfyhComm_data = Comm_options;
                };
                Comm_options.action();
            };
            return false;
        }).bind("mouseover", function() {
            if (goods_cart_btn) {return false};
            cartbtnsumitName = "#" + this.id;
            E();
            if (!E()) {
                $("#ark_addToCart,#ark_nowbuyToCart,#addFitToCart,#btn_goods_pointsexchange,#mypanicbuying,#ark_addmake").css("cursor", "not-allowed")
            } else {
                $("#ark_addToCart,#ark_nowbuyToCart,#addFitToCart,#btn_goods_pointsexchange,#mypanicbuying,#ark_addmake").css("cursor", "");
                if ($("#ark_addToCartIndicator")[0]) {
                    O.hide()
                }
            }
        }).bind("mouseout", function() {
            if (goods_cart_btn) {return false};
            cartbtnsumitName = "#" + this.id;
            $("#ark_addToCart,#ark_nowbuyToCart,#addFitToCart,#btn_goods_pointsexchange,#mypanicbuying,#ark_addmake").css("cursor", "");
            O.hide()
        });
        $("#ark_noAddToCart").bind("click", function() {
            var k = $("#ark_buy_itemId").val();
            var g = $("#ark_buy_itemDetailId").val();
            var j = [k, g];
            var url = lodo_web_path + "goodsnotify.asp?gid={0}";
			if(g!=""){url+="&item_detail_id={1}"};
            var h = substitute(url, j);
            $(this).attr("href", h);
            return false
        })
    };
    a.detachEventFromAddTrigger = function() {
        $("#ark_addToCart,#ark_nowbuyToCart,#addFitToCart,#btn_goods_pointsexchange,#ark_noAddToCart,#mypanicbuying,#ark_addmake").unbind("click").unbind("mouseover").unbind("mouseout");
        O.show($(cartbtnsumitName));
        O.reportFailed("<img src='images/zoomloader.gif' width='16px' height='16px'>"+lodo_lang_js.arkShopCart.tip_8);
        $(cartbtnsumitName).hide();
    };
	a.pro_post_cart2=function(gid,oaid,buyqn){
		var option={
			action:function(){
				var url=lodo_web_path+"cart2.asp?act=fastbuy&bn="+Math.random();
				$("#ark_cartForm").attr({"action":url}).submit();
			}
		}
		this.detachEventFromAddTrigger();
		$.getJSON(lodo_web_path+"ajax_data.asp?action=getuserlogininfo&gid="+gid+"&oaid="+oaid+"&buyqn="+buyqn+"",function(data){
			goods_cart_btn = false;
			O.hide();
			$(cartbtnsumitName).show();
			a.attachEventToAddTrigger();
			if(data.errno){alert(data.msg);return false;}
			if(data.gotono){location.href=data.gotourl};
			if(data.logno){
				$loginFrame({
					type:"func",
					check: false,
					checkReady:false,
					model: false,
					title:lodo_lang_js.arkShopCart.tip_9,
					gotourl:data.gotourl,
					action:option.action
				});
			}else{
				option.action();
			}
		})
	}
    a.addToCart = function(j) {
        this.detachEventFromAddTrigger();
        var g = "&t=" + (new Date()).getTime();
        var T = lodo_web_path + "addgoodscar.asp?act={0}&Gid={1}&item_detail_id={2}&quantity={3}&cgid={4}";
        var i = T + g;
        var h = substitute(i, j);
        var options = {
            url: h,
            dataType: "json",
            success: a.popupItemList
        };
        $("#ark_cartForm").ajaxSubmit(options);
        return false
    };
    a.popupItemList = function(data) {
        O.hide();
        $(cartbtnsumitName).show();
        a.attachEventToAddTrigger();
        if (data.errno) {
            alert(data.msg);
            return false
        }
        //if (data.gotono) {location.href = data.gotourl;};
        if (data.logno) {$GoodsJfyhComm(data.gotourl,{title:lodo_lang_js.functions.tip_25})};
        if (data.gotono) {if(data.msgno){alert(data.msg);}location.href = data.gotourl;return false;};
        /*if (data.logno) {
			var curModal=$(".pu_box").modal({
				opacity:70,
				escClose: true,
				close: true,
				overlayClose: true,
				closeClass: 'pu_close'
			});
			return false;
			//$GoodsJfyhComm(data.gotourl)
		};*/
        if (data.cartno) {
            O.show($(cartbtnsumitName), {isReportSuccess: "true"});
            O.reportSuccess(data);
			$("#ark_closeIndicator,#ark_continueShopping").live("click",function(){
				 goods_cart_btn = false;
				 O.hide();
				return;
			});
/*            $("#ark_closeIndicator,#ark_continueShopping").click(function() {
                goods_cart_btn = false;
                O.hide();
                return false
            })*/
        }
    };
    a._init = function() {
        this.attachEventToAddTrigger();
    };
    a._init();
    return a
});

function goods_load_init() {
    sellProps = OAitems["sellProps"];
    allItems = OAitems["allItems"];
    mealDetailPrice = [];
    defaultSelect = {};
    if (!$.isEmptyObject(sellProps)) {
        goodsStyleno = true;
        sellProperty[productID] = new spec_SellProperty("#ark_", sellProps, allItems, 
        function(argument) {
            var way = argument.way || 1;
            var pvSelected = argument.selected || false;
            var pvid = argument.pvid || '';
			var oneshow = argument.show || false;
            var currentPV = argument.currentPV || '';
            var name = argument.name || '';
            var itemMealPvid = pvid;
            var items = this.getSelectedItem();
            goodsStyleId = 0;
            goodsStyleName = "";
            if (items != null) {
                goodsStyleId = items.detailId;
                goodsStyleName = items.name
            };
            lodo_accessories();
            var tmp_pvid = pvid.split("_");
            var ark_spec_value = $("#ark_spec_value_" + tmp_pvid[0] + "[way!='3']");
            if (ark_spec_value[0]) {
                if (pvSelected) {
                    ark_spec_value.html(name)
                } else {
                    ark_spec_value.html(ark_spec_value.attr("tip"))
                }
                if (way != 1&&!oneshow) {
                    ark_spec_value.parent().click()
                }
            };
            var pic_list = [];
            for (var B = 0; B < this.selectCPID.length; B++) {
                var tmp_cpid = this.selectCPID[B];
                var tmp_pvid = this.selectPVID[tmp_cpid];
                var tmp_cpiclist = this.sellProps[tmp_cpid].pvs[tmp_pvid].cpiclist;
                for (var A = 0; A < tmp_cpiclist.length; A++) {
                    if (pic_list.indexOf(tmp_cpiclist[A]) == -1) {
                        pic_list.push(tmp_cpiclist[A])
                    }
                }
            };
            if (pic_list.length > 0) {
                $("#"+thumblist+">li>a>img").each(function() {
                    var tmp_pic = $(this).attr("src");
                    if (pic_list.indexOf(tmp_pic) == -1) {
                        $(this).parent().parent().hide()
                    } else {
                        $(this).parent().parent().show()
                    }
                })
            } else {
                $("#"+thumblist+">li").show()
            };
			if(lodo_jcarousel){lodo_jcarousel.scroll(1);}
			$("#"+thumblist+">li:visible:first>a").mouseover();
            if ($('#ark_info-hx')[0]) {
                if (this.isNoPVSelected()) {
                    var msg = this.getAllPVNames().join('", "');
                    $("#ark_info-hx").html(lodo_lang_js.arkShopCart.tip_2+' "' + msg + '"')
                } else {
                    var msg = this.getSelectedValueNames().join('", "');
                    $("#ark_info-hx").html(lodo_lang_js.arkShopCart.tip_10+'<em>"' + msg + '"</em>')
                }
            };
            $("#ark_addToCartIndicator").hide();
        },
        true);
        sellProperty[productID].setDefaultItemId(productID);
        sellProperty[productID].setDefaultSelect(defaultSelect);
        sellProperty[productID].setSellPropsCount(OAitems.length);
        sellProperty[productID].initload();
    } else {
        $("#ark_price1").hide();
        $("#ark_price2").show();
        var lodo_goods_quantity = $("#ark_buy_maxCount").val();
        if (lodo_goods_quantity != -1) {
            if (lodo_goods_quantity <= 0) {
                $("#ark_stock>em").html(lodo_lang_js.arkShopCart.tip_1);//此商品缺货中
                $("#ark_stock>span").hide();
                $("#ark_addToCart,#ark_addmake,#ark_nowbuyToCart").hide();
                $("#ark_noAddToCart").show()
            } else {
                $("#ark_stock>em").html(lodo_goods_quantity);
                $("#ark_stock>span").show();
                $("#ark_addToCart,#ark_addmake,#ark_nowbuyToCart").show();
                $("#ark_noAddToCart").hide();
            }
        } else {
            $("#ark_stock>em").html(lodo_lang_js.arkShopCart.tip_11);
            $("#ark_stock>span").hide();
			//$("#ark_stock>span").show();
			$("#ark_addToCart,#ark_addmake,#ark_nowbuyToCart").show();
			$("#ark_noAddToCart").hide();
        }

        var A = $("#ark_goodsdynamic")[0] ? $("#ark_goodsdynamic").attr("gprice") : 0;
        var g_points = $("#ark_goodsdynamic")[0] ? $("#ark_goodsdynamic").attr("gpoints") : 0;
        var B = $("#ark_accessoriesinfo");
        var C = 0;
        var L = $("#ark_buy_itemId").val();
        var D = $("#ark_buyqn") ? parseInt($("#ark_buyqn").val()) : 1;
        if (isfloat(A)) {
            C += (A * D);
            C = FormatNumber(C, 2);
            $("#ark_goodsdynamic>span.totalinfo>i.g-total-price").html(C)
        } else {
            C = A;
            $("#ark_priceSave").parent().hide();
            $("#ark_goodsdynamic>span.totalinfo>i.g-total-price").parent().html("<i class='g-total-price'>" + C + "</i>")
        }
        g_points *= D;
        $("#ark_goodsdynamic>span.totalinfo>i.g-total-points").html(g_points);
        iSum = A;
        total_goods_sum = C;
        $("#goods_style_info").html(productName);
        $("#mobileNum").html($("#ark_buyqn").val());
        $("#fitting_sum").html(total_goods_sum);
        $("#styleFittSum").show();
        if (!isfloat(total_goods_sum)) {
            $("#styleFittSum>i").hide()
        } else {
            $("#styleFittSum>i").show()
        }
    };
	$("form#ark_cartForm #ark_buyqn").blur(function() {
		goods_stock_verify("ark_");
	});
	$("form#ark_cartForm #ark_addgoodsnum").click(function() {
		good_cal("ark_",1);
		return false
	});
	$("form#ark_cartForm #ark_lessgoodsnum").click(function() {
		good_cal("ark_",-1);
		return false
	})
    ShoppingCart();
}
function load_goods_fittings() {
    $('#chooseFitt').live("click", function() {
        $('#getFittings>li>a').removeClass('slct_pdnav');
        $('#getFittings_rht>li').removeClass('li_ghtslect');
        $('#getFittings_rht>li:last').addClass('li_ghtslect');
        $('#getFittings_rht>li:last span').show();
        $('#fittingUl').attr('cid', 0);
        $('#fittingUl>li').not('#noneFitt').each(function() {
            var num = $(this).find("input[name^='fitting_goods_num_" + productID + "_']").attr("checked");
            if (num) {
                $(this).show()
            } else {
                $(this).hide()
            }
        });
        var is_display = $("#fittingUl>li:visible").size();
        if ((is_display == 1 && $('#noneFitt').css('display') != 'none') || is_display == 0) {
            $('#noneFitt').show()
        } else {
            $('#noneFitt').hide()
        }
		gotomove();
    });
    $('#getFittings li a').live("click", function() {
        $('#getFittings li a').removeClass('slct_pdnav');
        $('#getFittings_rht li').removeClass('li_ghtslect');
        $(this).addClass('slct_pdnav')
    });
    $('#getFittings li:eq(0) a').addClass('slct_pdnav');
    show_fittings(productID, [ - 1]);
}
function lodo_accessories() {
    var lodo_goods_quantity = $("#ark_buy_maxCount").val() * 1;
    var A = $("#ark_goodsdynamic")[0] ? $("#ark_goodsdynamic").attr("gprice") : 0;
    var g_points = $("#ark_goodsdynamic")[0] ? $("#ark_goodsdynamic").attr("gpoints") : 0;
    var B = $("#ark_accessoriesinfo");
    var C = 0;
    var L = $("#ark_buy_itemId").val();
    var D = $("#ark_buyqn") ? parseInt($("#ark_buyqn").val()) : 1;
    if (D > lodo_goods_quantity && lodo_goods_quantity != -1) {
        D = lodo_goods_quantity;
        $("#ark_buyqn").val(D)
    }

	
	//判断是否达到批发方案的条件
	$("#goods_wholesale_tip").hide();
	if(product_wholesale[productID]){
		for(var I=0;I<product_wholesale[productID].length;I++){
			var wp_buyqn=product_wholesale[productID][I].buyqn;
			var wp_Discount=product_wholesale[productID][I].Discount;
			if(D>=wp_buyqn){
				A=FormatNumber(A*(wp_Discount/100),2);
				$("#goods_wholesale_tip>.wp_buyqn").html(wp_buyqn);
				$("#goods_wholesale_tip>.wp_discount").html((wp_Discount/10));
				$("#goods_wholesale_tip").show();
				break;
			}
		}
	}	
	
    if (isfloat(A)) {
        C += (A * D);
        C = FormatNumber(C, 2)
    } else {
        C = A
    }	

	
    g_points *= D;
    $("#ark_goodsdynamic>span.totalinfo>i.g-total-price").html(C);
    $("#ark_goodsdynamic>span.totalinfo>i.g-total-points").html(g_points);
    iSum = A;
    total_goods_sum = C;
    if (goodsStyleId == 0 && goodsStyleno) {
        $("#goods_style_info,#fitting_sum").html("\u8BF7\u5148\u9009\u62E9\u5546\u54C1\u89C4\u683C");
        $("#mobileNum").html(0);
        $("#styleFittSum,#fitting_ex,#styleFittSum>i").hide()
    } else {
        var goods_style_info = productName;
        if (goodsStyleName != "") {
            goods_style_info += "(" + goodsStyleName + ")"
        }
        $("#goods_style_info").html(goods_style_info);
        $("#mobileNum").html(D);
        $("#fitting_sum").html(total_goods_sum);
        $("#styleFittSum").show();
        if (!isfloat(total_goods_sum)) {
            $("#styleFittSum>i").hide()
        } else {
            $("#styleFittSum>i").show()
        }
        total_goods_price();
    }
}
function show_fittings(a, b) {
    $("#fittingUl").attr("cid", b[0]);
    if (b[0] == -1) {
        $("#fittingUl>li").show();
        $("#noneFitt").hide()
    } else {
        $("#fittingUl>li").hide();
        $("#fittingUl>li.fit[fittid='" + b[0] + "']").show()
    }
};
var goodsStyleId = 0;
var goodsStyleName = "";
var lodo_path_img = "";
var sum = total_goods_sum = iSum = 0;
var g_fitt_price = 0;
var mp = 0;
var goodsStyleno = false;
function add_sub_cart(aid, gid, specno, tcno, tcw, tch) {
    if ((goodsStyleno && goodsStyleId == 0)) {
        alert("\u8BF7\u5148\u9009\u62E9\u5546\u54C1\u89C4\u683C");
        return false
    };
    var aid_gid = aid + "_" + gid;
    var b = $("#btn_fitting_" + aid_gid);
    var l = $("#fitting_goods_num_" + aid_gid);
    var h = 0;
    if (l.attr("checked")) {
        l.attr("checked", false);
        b.attr("src", lodo_path_img + "buyGoods_1.gif");
        $("#fitt_group_" + aid_gid).removeClass("choose");
        h = $("#fittingUl>li.fit:visible").size();
        if (h == 0) {
            $("#noneFitt").show()
        }
        $("#fitt_goods_spec_" + aid_gid).html("").hide();
        $("#fitt_goods_spec_info_" + aid_gid).show()
    } else {
        if (specno == 1) {
            if (tcno == "true") {
                tc_goods_no = true;
                var tc_width = 800;
                var tc_height = 600;
                if (tcw != null && tcw != undefined && tcw != "") {
                    tc_width = tcw * 1
                }
                if (tch != null && tch != undefined && tch != "") {
                    tc_height = tch * 1
                }
                $.fancybox.showActivity();
                $.get(lodo_web_path+"goodsinfo.asp?act=accessories&gid=" + gid + "&aid=" + aid + "&bn=" + Math.random(), 
                function(data) {
                    $.fancybox(data, {
                        'autoDimensions': false,
                        'width': tc_width,
                        'height': tc_height,
                        'transitionIn': 'none',
                        'transitionOut': 'none',
                        onClosed: function() {
                            tc_goods_no = false
                        }
                    })
                })
            } else {
                fit_addToCart(aid, gid, fit_sellProperty[aid_gid])
            }
            return false
        } else {
            l.attr("checked", true);
            b.attr("src", lodo_path_img + "cancelGoods_1.gif");
            $("#fitt_group_" + aid_gid).addClass("choose")
        }
    }
    total_goods_price();
    return false
}
function edit_sub_cart(e) {
    var input_buynum = $(e);
    var minsum = input_buynum.attr("minsum") * 1;
    var maxsum = input_buynum.attr("maxsum") * 1;
    var buynum = input_buynum.val() * 1;
    if (!isDigit(buynum)) {
        alert(lodo_lang_js.arkShopCart.tip_13);
        input_buynum.val(minsum);
        return false
    }
    if (buynum < minsum) {
        alert(lodo_lang_js.arkShopCart.tip_14.replace("{$1}",minsum));
        input_buynum.val(minsum);
        return false
    }
    if (buynum > maxsum && maxsum != -1) {
        alert(lodo_lang_js.arkShopCart.tip_15.replace("{$1}",maxsum));
        input_buynum.val(minsum);
        return false
    }
    total_goods_price()
}
function total_goods_price() {
    if (isfloat(total_goods_sum)) {
        total_goods_sum *= 1
    };
    var c = 0;
    var d = sum = total_goods_sum;
    g_fitt_price = 0;
    $("#accessories_goods_select_list>li").remove();
    $("input:checkbox[name^='fitting_goods_num_']:checked").each(function() {
        var fit_id = $(this).attr("fit_id");
        var gid = $(this).val();
        var gname = $(this).attr("gname");
        var aid_gid = fit_id + "_" + gid;
        var tmp_f_goods_price = parseFloat($("#fitting_goods_price_" + aid_gid).val());
        var tmp_f_shop_price = parseFloat($("#fitting_shop_price_" + aid_gid).val());
        var tmp_buynum = parseInt($("#fit_" + aid_gid + "_buyqn").val());
        c += tmp_buynum;
        tmp_f_goods_price = tmp_f_goods_price * tmp_buynum;
        tmp_f_shop_price = tmp_f_shop_price * tmp_buynum;
        g_fitt_price += tmp_f_goods_price;
        d += tmp_f_shop_price;
        var gpic = $("#fit_pic_addr_" + aid_gid).attr("src");
        var gspecname = $("#fitting_itemDetailId_" + aid_gid).attr("gname");
        if (gspecname != "") {
            gname += "(" + gspecname + ")"
        };
        var tmp_li = $("<li></li>");
        tmp_li.append("<div class=pic><img src='" + gpic + "' width=80 height=80></div>");
        var tmp_div = $("<div class=info></div>");
        tmp_div.append("<div class=name>" + gname + "</div>");
        tmp_div.append("<div class=price><span class=title>"+lodo_lang_js.arkShopCart.tip_16+"：</span>" + tmp_f_goods_price + lodo_lang_yuan + "</div>");
        tmp_div.append("<div class=buyqn><span class=title>"+lodo_lang_js.arkShopCart.tip_17+"：</span>" + tmp_buynum + lodo_lang_js.arkShopCart.tip_24+"</div>");
        tmp_div.append("<div class=close><span class='delX' onclick='add_sub_cart(" + fit_id + "," + gid + ",0,false);'>"+lodo_lang_js.arkShopCart.tip_18+"</span></div>");
        tmp_li.append(tmp_div);
        $("#accessories_goods_select_list").append(tmp_li)
    });
    $("#fitting_cnt,#chooseFittNum").html(c.toString());
    var f_ex_sum = sum;
    if (isfloat(sum)) {
        sum += g_fitt_price;
        sum = FormatNumber(sum, 2);
        f_ex_sum = FormatNumber((d * 1 - sum * 1), 2);
        $("#fitting_sum").html(sum);
        $("#select_fitt_price").html("\uffe5" + FormatNumber(g_fitt_price, 2));
        $("#fitting_ex").html(c > 0 ? ('\u8282\u7701:<span class="bRed">\uffe5' + f_ex_sum + "</span>") : "").show()
    }
}

//商品库存验证
function goods_stock_verify(ot){
	var e=$("#"+ot+"buyqn");
	var goods_qn=$("#"+ot+"buy_maxCount").val()*1;
    var max_buyqn = $("#"+ot+"buy_maxQn").val() * 1;
    var min_buyqn = $("#"+ot+"buy_minQn").val() * 1;
	var buyqn=e.val()*1;//购买的数量
	var lv=e.attr("lv")*1;
	var lvtyp=e.attr("lvtyp")*1;//0按倍数计算,1按正常计算
	var no=true;
	if(!isDigit(buyqn)){
		alert(lodo_lang_js.arkShopCart.tip_19);
		no=false;
	}else{
		if(buyqn>goods_qn&&(goods_qn!=-1)){
			alert(lodo_lang_js.arkShopCart.tip_20.replace("{$1}",goods_qn));
			no=false;
		}else{
			if(buyqn>max_buyqn&&(max_buyqn!=-1)){
				alert(lodo_lang_js.arkShopCart.tip_5.replace("{$1}",max_buyqn));
				no=false;
			}else{
				if(lvtyp==0){
					if ( (buyqn<=0 || (buyqn % lv) != 0)){
						alert(lodo_lang_js.arkShopCart.tip_6.replace("{$1}",lv));
						no=false;
					}
				}else{
					if(buyqn<min_buyqn){
						alert(lodo_lang_js.arkShopCart.tip_7.replace("{$1}",lv));
						no=false;
					}
				}
			}
		}
	}
	if(!no){
		e.val(lv);
	}else{
		e.val(buyqn);
	}
	lodo_accessories();
}
function good_cal(ot,typ) {
	var e=$("#"+ot+"buyqn");
	var buyqn=$(e).val()*1;//购买的数量
	var lv=$(e).attr("lv")*1;
	var lvtyp=$(e).attr("lvtyp")*1;//0按倍数计算,1按正常计算
	var s=1;
	if(lvtyp==0){s=lv;}
	s*=typ;
	buyqn+=s;
	e.val(buyqn);
	goods_stock_verify(ot);
}

var tc_sellProperty = {};
var tc_productID = 0;
var tc_goods_no = false;
var tc_cartbtnsumitName;
var tc_ShoppingCart = (function() {
    var Q = lodo_lang_js.arkShopCart.tip_1;//此商品缺货中
    var N = lodo_lang_js.arkShopCart.tip_2;//请选择：
    var K = lodo_lang_js.arkShopCart.tip_3;//请填写正确的商品数量！
    var U = lodo_lang_js.arkShopCart.tip_4;//您是卖家，不能添加到购物车
    var O = new cart_r_cls();
    var I = function(g) {
        O.show($(tc_cartbtnsumitName));
        O.reportFailed(g)
    };
    var E = function() {
        var j = $("#ark_listCart");
        if (!j[0]) {
            I(U);
            return false
        }
        if (typeof(tc_sellProperty[tc_productID]) != "undefined") {
            if (!tc_sellProperty[tc_productID].isAllPVSelected()) {
                var k = tc_sellProperty[tc_productID].getUnselectedPVNames().join('", "');
                I(N + ' "' + k + '"');
                $("#tc_ark_info-hx").html("<em>" + N + ' "' + k + '"</em>');
                return false
            }
        };
        var m = $("#tc_ark_buy_maxCount");
        var l = $("#tc_ark_buyqn");
        if (!m[0]) {
            return false
        }
        if (!l[0]) {
            return false
        };
        var i = /^[1-9]\d*$/;
        if (!i.test(l.val().replace(/(^\s*)|(\s*$)/g, ""))) {
            I(K);
            return false
        };
		
        var h = parseInt(l.val());
        var g = parseInt(m.val());
        var lv = l.attr("lv");
        var lvtyp = l.attr("lvtyp");
        if (g == 0) {
            I(Q);
            return false
        }
        if (h > g && g != -1) {
            I(lodo_lang_js.arkShopCart.tip_5.replace("{$1}",g));
            return false
        }
		
		if(lvtyp==0){
		if ( (h<=0 || (h % lv) != 0)){
				I(lodo_lang_js.arkShopCart.tip_6.replace("{$1}",lv));
				return false;
			}
		}else{
			if(h<lv){
				I(lodo_lang_js.arkShopCart.tip_7.replace("{$1}",lv));
				return false;
			}
		}
        return true
    };
    var a = {};
    a.attachEventToAddTrigger = function() {
        $("#tc_ark_sellProperty_area").hover(function() {
            $(this).addClass("no-selceted");
            return false
        },
        function() {
            $(this).removeClass("no-selceted");
            return false
        });
        $("#tc_ark_addToCart,#tc_ark_addmake").live("click", 
        function() {
            if ( !! E()) {
                var k = $("#tc_ark_buy_itemId").val();
                var g = $("#tc_ark_buy_itemDetailId").val();
                var i = $("#tc_ark_buyqn").val();
                tc_cartbtnsumitName = this;
				switch (this.id) {
					case "tc_ark_addmake":{
							addtomake(k, g, i,"tc");
							return false;
							break
						}
				}
                var j = [k, g, i];
                a.addToCart(j)
            }
            return false
        }).live("mouseover", 
        function() {
            tc_cartbtnsumitName = this;
            E();
            if (!E()) {
                $("#tc_ark_addToCart,#ark_addmake").css("cursor", "not-allowed")
            } else {
                $("#tc_ark_addToCart,#ark_addmake").css("cursor", "");
                if ($("#tc_ark_addToCartIndicator")[0]) {
                    O.hide()
                }
            }
        }).live("mouseout", 
        function() {
            tc_cartbtnsumitName = this;
            $("#tc_ark_addToCart,#ark_addmake").css("cursor", "");
            O.hide()
        });
        $("#tc_ark_noAddToCart").live("click", 
        function() {
            var k = $("#tc_ark_buy_itemId").val();
            var g = $("#tc_ark_buy_itemDetailId").val();
            var j = [k, g];
            var url = lodo_web_path + "goodsnotify.asp?gid={0}&item_detail_id={1}";
            var h = substitute(url, j);
            $(this).attr("href", h);
            return false
        })
    };
    a.addToCart = function(j) {
        var gid = j[0];
        var aid = tc_goods_info_json.aid;
        fit_addToCart(aid, gid, tc_sellProperty[gid]);
        $.fancybox.close();
        return false
    };
    a._init = function() {
        this.attachEventToAddTrigger()
    };
    a._init();
    return a
});
function fit_addToCart(aid, gid, items) {
    var fitt_goods_spec = $("<ul></ul>");
    var fitting_itemDetailId = 0;
    var gspecname = "";
    if (items) {
        if (!$.isEmptyObject(items)) {
            var tmp_sellProps = items.sellProps;
            for (var A in tmp_sellProps) {
                var C = items.selectPVID[A];
                var way = tmp_sellProps[A].way;
                var typ = tmp_sellProps[A].type;
                var s_t_name = tmp_sellProps[A].name;
                var s_t_i_name = tmp_sellProps[A].pvs[C].name;
                var tmp_li = $("<li><em>" + s_t_name + "：</em></li>");
                if (typ == 1) {
                    tmp_li.append("<a href='javascript:void(0);'><span>" + s_t_i_name + "</span><i>selected</i></a>")
                } else {
                    var s_t_i_picaddr = tmp_sellProps[A].pvs[C].picaddr;
                    tmp_li.append("<a href='javascript:void(0);'><span><img src='" + s_t_i_picaddr + "' title='" + s_t_i_name + "' width=32 height=32></span><i>selected</i></a>")
                }
                fitt_goods_spec.append(tmp_li);
                if (gspecname != "") {
                    gspecname += ","
                }
                gspecname += tmp_sellProps[A].pvs[C].name
            }
        };
        var selecteditems = items.getSelectedItem();
        if (selecteditems != null) {
            fitting_itemDetailId = selecteditems.detailId
        }
    };
    var aid_gid = aid + "_" + gid;
    $("#fitting_itemDetailId_" + aid_gid).attr("gname", gspecname).val(fitting_itemDetailId);
    $("#fitt_goods_spec_" + aid_gid).append(fitt_goods_spec).show();
    $("#fitt_goods_spec_info_" + aid_gid).hide();
    $("#fitting_goods_num_" + aid_gid).attr("checked", true);
    $("#btn_fitting_" + aid_gid).attr("src", lodo_path_img + "cancelGoods_1.gif");
    $("#fitt_group_" + aid_gid).addClass("choose");
    total_goods_price()
};
function tc_goods_load_init(obj) {
    var tc_goods_json = obj;
    tc_productID = tc_goods_json.gid;
    var sellProps = tc_goods_json.gspec["sellProps"];
    var allItems = tc_goods_json.gspec["allItems"];
    var defaultSelect = {};
    if (!$.isEmptyObject(sellProps)) {
        tc_sellProperty[tc_productID] = new spec_SellProperty("#tc_ark_", sellProps, allItems, 
        function(argument) {
            var way = argument.way || 1;
            var pvSelected = argument.selected || false;
            var pvid = argument.pvid || '';
            var currentPV = argument.currentPV || '';
            var name = argument.name || '';
            var itemMealPvid = pvid;
            var tmp_pvid = pvid.split("_");
            var ark_spec_value = $(this.idPrefix + "spec_value_" + tmp_pvid[0] + "[way!='3']");
            if (ark_spec_value[0]) {
                if (pvSelected) {
                    ark_spec_value.html(name)
                } else {
                    ark_spec_value.html(ark_spec_value.attr("tip"))
                }
                if (way != 1) {
                    ark_spec_value.parent().click()
                }
            };
            var pic_list = [];
            for (var B = 0; B < this.selectCPID.length; B++) {
                var tmp_cpid = this.selectCPID[B];
                var tmp_pvid = this.selectPVID[tmp_cpid];
                var tmp_cpiclist = this.sellProps[tmp_cpid].pvs[tmp_pvid].cpiclist;
                for (var A = 0; A < tmp_cpiclist.length; A++) {
                    if (pic_list.indexOf(tmp_cpiclist[A]) == -1) {
                        pic_list.push(tmp_cpiclist[A])
                    }
                }
            }
            if (pic_list.length > 0) {
                $("#tc_thumblist>li>a>img").each(function() {
                    var tmp_pic = $(this).attr("src");
                    if (pic_list.indexOf(tmp_pic) == -1) {
                         $(this).parent().parent().hide()
                    } else {
                        $(this).parent().parent().show()
                    }
                })
            } else {
                $("#tc_thumblist>li").show()
            }
			$("#tc_thumblist>li:visible:first>a").mouseover();
            if ($('#tc_ark_info-hx')[0]) {
                if (this.isNoPVSelected()) {
                    var msg = this.getAllPVNames().join('", "');
                    $("#tc_ark_info-hx").html(lodo_lang_js.arkShopCart.tip_2+' "' + msg + '"')
                } else {
                    var msg = this.getSelectedValueNames().join('", "');
                    $("#tc_ark_info-hx").html(lodo_lang_js.arkShopCart.tip_10+'<em>"' + msg + '"</em>')
                }
            }
            $("#tc_ark_addToCartIndicator").hide()
        });
        tc_sellProperty[tc_productID].setDefaultItemId(tc_productID);
        tc_sellProperty[tc_productID].setDefaultSelect(defaultSelect);
        tc_sellProperty[tc_productID].setSellPropsCount(tc_goods_json.gspec.length);
        tc_sellProperty[tc_productID].initload();
    } else {
        $("#tc_ark_price1").hide();
        $("#tc_ark_price2").show();
        var lodo_goods_quantity = $("#tc_ark_buy_maxCount").val() * 1;
        if (lodo_goods_quantity != -1) {
            if (lodo_goods_quantity <= 0) {
                $("#tc_ark_stock>em").html("\u6B64\u5546\u54C1\u7F3A\u8D27\u4E2D");//此商品缺货中
                $("#tc_ark_stock>span").hide();
                $("#tc_ark_addToCart,#tc_ark_nowbuyToCart").hide();
                $("#tc_ark_noAddToCart").show()
            } else {
                $("#tc_ark_stock>em").html(lodo_goods_quantity);
                $("#tc_ark_stock>span").show();
                $("#tc_ark_addToCart,#tc_ark_nowbuyToCart").show();
                $("#tc_ark_noAddToCart").hide()
            }
        } else {
            $("#tc_ark_stock>em").html(lodo_lang_js.arkShopCart.tip_11);//长期提供
            $("#tc_ark_stock>span").hide()
        }
    }
	
	$("form#tc_ark_cartForm #tc_ark_buyqn").blur(function() {
		goods_stock_verify("tc_ark_");
		return false;
	});
	$("form#tc_ark_cartForm #tc_ark_addgoodsnum").click(function() {
		good_cal("tc_ark_",1);
		return false
	});
	$("form#tc_ark_cartForm #tc_ark_lessgoodsnum").click(function() {
		good_cal("tc_ark_",-1);
		return false
	})
    tc_ShoppingCart()
};
var fit_cartbtnsumitName;
var fit_aid_gid = "";
var FIT_Meal = (function() {
    var Q = lodo_lang_js.arkShopCart.tip_1;//此商品缺货中
    var N = lodo_lang_js.arkShopCart.tip_2;//请选择：
    var K = lodo_lang_js.arkShopCart.tip_3;//请填写正确的商品数量
    var lang_select = lodo_lang_js.arkShopCart.tip_12;//请选择商品规格
    var O = new cart_r_cls();
    var I = function(g) {
        O.show($(fit_cartbtnsumitName));
        O.reportFailed(g)
    };
    var E = function() {
        O.hide();
        $(fit_cartbtnsumitName).show();
        var j = $("#ark_listCart");
        if (!j[0]) {
            I(U);
            return false
        }
        if ((goodsStyleno && goodsStyleId == 0)) {
            I(lang_select);
            return false
        };
        var tc = $(fit_cartbtnsumitName).attr("tc");
        if (tc == "true") {return true;}
        if (typeof(fit_sellProperty[fit_aid_gid]) != "undefined") {
            if (!fit_sellProperty[fit_aid_gid].isAllPVSelected()) {
                var k = fit_sellProperty[fit_aid_gid].getUnselectedPVNames().join('", "');
                I(N + ' "' + k + '"');
                $("#fit_" + fit_aid_gid + "_info-hx").html("<em>" + N + ' "' + k + '"</em>');
                return false
            }
        };
        var m = $("#fit_" + fit_aid_gid + "_buy_maxCount");
        var l = $("#fit_" + fit_aid_gid + "_buyqn");
        var buy_minqn = $("#fit_" + fit_aid_gid + "_minbuyqn");
        var buy_maxqn = $("#fit_" + fit_aid_gid + "_maxbuyqn");
        if (!m[0]) {
            return false
        }
        if (!l[0]) {
            return false
        }
        if (!buy_minqn[0]) {
            return false
        }
        if (!buy_maxqn[0]) {
            return false
        };
        var i = /^[1-9]\d*$/;
        if (!i.test(l.val().replace(/(^\s*)|(\s*$)/g, ""))) {
            I(K);
            return false
        };
        var h = parseInt(l.val());
        var g = parseInt(m.val());
        var bminqn = parseInt(buy_minqn.val());
        var bmaxqn = parseInt(buy_maxqn.val());
        if (g == 0) {
            I(Q);
            return false
        }
        if (h > g && g != -1) {
			I(lodo_lang_js.arkShopCart.tip_5.replace("{$1}",g));
            return false
        }
        if (h < bminqn && bminqn != -1) {
            I(lodo_lang_js.arkShopCart.tip_21.replace("{$1}",bminqn));
            return false
        }
        if (h > bmaxqn && bmaxqn != -1) {
            I(lodo_lang_js.arkShopCart.tip_22.replace("{$1}",bmaxqn));
            return false
        };
        var buyqn_total = h;
        return true
    };
    var a = {};
    a.attachEventToAddTrigger = function() {
        $("div[id$='_sellProperty_area']").hover(function() {
            $(this).addClass("no-selceted");
            return false
        },
        function() {
            $(this).removeClass("no-selceted");
            return false
        });
        $(".btn_fitting_buy").live("click", 
        function() {
            var fit_id = $(this).attr("fit_id");
            var gid = $(this).attr("gid");
            var tc = $(this).attr("tc");
            var tcw = $(this).attr("tcw");
            var tch = $(this).attr("tch");
            var specno = $(this).attr("specno");
            fit_aid_gid = fit_id + "_" + gid;
            var k = $("#fit_" + fit_aid_gid + "_buy_itemId").val();
            var g = $("#fit_" + fit_aid_gid + "_buy_itemDetailId").val();
            var i = $("#fit_" + fit_aid_gid + "_buyqn").val();
            fit_cartbtnsumitName = this;
            if ( !! E()) {
                add_sub_cart(fit_id, gid, specno, tc, tcw, tch)
            }
            return false
        }).live("mouseover", 
        function() {
            var fit_id = $(this).attr("fit_id");
            var gid = $(this).attr("gid");
            fit_aid_gid = fit_id + "_" + gid;
            fit_cartbtnsumitName = this;
            E();
            if (!E()) {
                $(this).css("cursor", "not-allowed")
            } else {
                $(this).css("cursor", "");
                if ($("#ark_addToCartIndicator")[0]) {
                    O.hide()
                }
            }
        }).live("mouseout", 
        function() {
            var fit_id = $(this).attr("fit_id");
            var gid = $(this).attr("gid");
            fit_aid_gid = fit_id + "_" + gid;
            fit_cartbtnsumitName = this;
            $(this).css("cursor", "");
            O.hide()
        });
        $(".baddtocart").live("click", 
        function() {
            fit_cartbtnsumitName = this;
            var fit_id = $(this).attr("bgid");
            var url = "";
            var btotalNum = 0;
            var buyqn_total = 0;
            for (var I in lodo_fit_Meal_list) {
                var tmp_meal = lodo_fit_Meal_list[I];
                if (!$.isEmptyObject(tmp_meal)) {
                    btotalNum++;
                    if (url != "") {
                        url += "&"
                    }
                    url += "gid_" + btotalNum + "=" + tmp_meal.gid;
                    url += "&oaid_" + btotalNum + "=" + tmp_meal.oaid;
                    url += "&buyqn_" + btotalNum + "=" + tmp_meal.buyqn;
                    buyqn_total += tmp_meal.buyqn
                }
            };
            var fit_buyQn_Total = $("#fit_buyQn_Total").val() * 1;
            if (buyqn_total != fit_buyQn_Total) {
                alert(lodo_lang_js.arkShopCart.tip_23.replace("{$1}",fit_buyQn_Total));
                return false
            };
            if (url != "") {
                url = "&" + url
            }
            url = lodo_web_path+"addbindgoodstocart.asp?act=add&gid=" + fit_id + url;
            a.detachEventFromAddTrigger();
            $.getJSON(url, 
            function(data) {
                O.hide();
                $(fit_cartbtnsumitName).show();
                if (data.errno) {
                    alert(data.msg);
                    return false
                };
                if (data.gotono) {
                    location.href = data.gotourl
                };
                if (data.cartno) {
                    O.show($(fit_cartbtnsumitName), {
                        isReportSuccess: "true"
                    });
                    O.reportSuccess(data);
                    a.attachEventToAddTrigger();
					$("#ark_continueShopping,#ark_closeIndicator").live("click",function(){
                        O.hide();
                        return false
					});
/*                    $("#ark_closeIndicator").live("click", function() {
                        O.hide();
                        return false
                    })*/
                }
            })
        })
    };
    a.detachEventFromAddTrigger = function() {
        $(".btn_fitting_buy,.baddtocart").die("click");
        O.show($(fit_cartbtnsumitName));
        O.reportFailed("<img src='images/loading3.gif' width='16px' height='16px'>"+lodo_lang_js.arkShopCart.tip_8);
        $(fit_cartbtnsumitName).hide()
    };
    a._init = function() {
        this.attachEventToAddTrigger()
    };
    a._init();
    return a
});
var goods_accessories_spec_json = {};
var fit_sellProperty = {};
function load_goods_accessories_json() {
    fit_sellProperty = {};
    if (!$.isEmptyObject(goods_accessories_spec_json)) {
        for (var I in goods_accessories_spec_json) {
            var items = goods_accessories_spec_json[I];
            var sellProps = items["sellProps"];
            var allItems = items["allItems"];
            var mealDetailPrice = [];
            var defaultSelect = {};
            var tmp_fit_gid = allItems[0].itemid;
            var tmp_idPrefix = "#fit_" + I + "_";
            if (!$.isEmptyObject(sellProps)) {
                fit_sellProperty[I] = new spec_SellProperty(tmp_idPrefix, sellProps, allItems, 
                function(argument) {
                    var way = argument.way || 1;
                    var pvSelected = argument.selected || false;
                    var pvid = argument.pvid || '';
                    var currentPV = argument.currentPV || '';
                    var name = argument.name || '';
                    var itemMealPvid = pvid;
                    var defaultItemId = argument.defaultItemId;
                    var tmp_pvid = pvid.split("_");
                    var ark_spec_value = $(this.idPrefix + "spec_value_" + tmp_pvid[0] + "[way!='3']");
                    if (ark_spec_value[0]) {
                        if (pvSelected) {
                            ark_spec_value.html(name)
                        } else {
                            ark_spec_value.html(ark_spec_value.attr("tip"))
                        }
                        if (way != 1) {
                            ark_spec_value.parent().click()
                        }
                    }
                    if ($(this.idPrefix + "info-hx")[0]) {
                        if (this.isNoPVSelected()) {
                            var msg = this.getAllPVNames().join('", "');
                            $(this.idPrefix + "info-hx").html(lodo_lang_js.arkShopCart.tip_2+' "' + msg + '"')
                        } else {
                            var msg = this.getSelectedValueNames().join('", "');
                            $(this.idPrefix + "info-hx").html(lodo_lang_js.arkShopCart.tip_10+'<em>"' + msg + '"</em>')
                        }
                    };
                    $("#ark_addToCartIndicator").hide()
                });
                fit_sellProperty[I].setDefaultItemId(tmp_fit_gid);
                fit_sellProperty[I].setDefaultSelect(defaultSelect);
                fit_sellProperty[I].setSellPropsCount(items.length);
                fit_sellProperty[I].initload()
            }
        }
    } else {
        $(tmp_idPrefix + "price1").hide();
        $(tmp_idPrefix + "price2").show();
        var lodo_goods_quantity = $(tmp_idPrefix + "buy_maxCount").val();
        if (lodo_goods_quantity != -1) {
            if (lodo_goods_quantity <= 0) {
                $(tmp_idPrefix + "stock>em").html(lodo_lang_js.arkShopCart.tip_1);//此商品缺货中
                $(tmp_idPrefix + "stock>span").hide();
                $(tmp_idPrefix + "addToCart," + tmp_idPrefix + "nowbuyToCart").hide();
                $(tmp_idPrefix + "noAddToCart").show()
            } else {
                $(tmp_idPrefix + "stock>em").html(lodo_goods_quantity);
                $(tmp_idPrefix + "stock>span").show();
                $(tmp_idPrefix + "addToCart," + tmp_idPrefix + "nowbuyToCart").show();
                $(tmp_idPrefix + "noAddToCart").hide()
            }
        } else {
            $(tmp_idPrefix + "stock>em").html(lodo_lang_js.arkShopCart.tip_11);
            $(tmp_idPrefix + "stock>span").hide()
        }
    };
    FIT_Meal()
}